package com.woniu.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SendCodeMQConfig {
    private static final String SEND_LOGIN_CODE_QUEUE_NAME = "sendLoginCodeQueue";
    private static final String SEND_REGISTER_CODE_QUEUE_NAME = "sendRegisterCodeQueue";
    private static final String SEND_CODE_EXCHANGE_NAME = "sendCodeExchange";
    private static final String SEND_LOGIN_CODE_ROUTING_KEY = "sendLoginCode";
    private static final String SEND_REGISTER_CODE_ROUTING_KEY = "sendRegisterCode";
    private static final String SEND_FORGET_PASSWORD_CODE_QUEUE_NAME = "sendForgetPasswordCodeQueue";
    private static final String SEND_FORGET_PASSWORD_CODE_ROUTING_KEY = "sendForgetPasswordCode";


    /**
     * 发送登录验证码的消息队列
     *
     * @return
     */
    @Bean
    public Queue sendLoginCodeQueue() {
        return new Queue(SEND_LOGIN_CODE_QUEUE_NAME);
    }

    /**
     * 发送注册验证码的消息队列
     *
     * @return
     */
    @Bean
    public Queue sendRegisterCodeQueue() {
        return new Queue(SEND_REGISTER_CODE_QUEUE_NAME);
    }

    /**
     * 发送忘记密码时修改密码的消息队列
     *
     * @return
     */
    @Bean
    public Queue sendForgetPasswordCodeQueue() {
        return new Queue(SEND_FORGET_PASSWORD_CODE_QUEUE_NAME);
    }

    /**
     * 通用交换机
     *
     * @return
     */
    @Bean
    public DirectExchange sendCodeExchange() {
        return new DirectExchange(SEND_CODE_EXCHANGE_NAME);
    }

    /**
     * 发送登录验证码
     *
     * @return
     */
    @Bean
    public Binding sendLoginCodeBinding() {
        return BindingBuilder.bind(sendLoginCodeQueue())
                .to(sendCodeExchange())
                .with(SEND_LOGIN_CODE_ROUTING_KEY);
    }

    /**
     * 发送注册验证码
     *
     * @return
     */
    @Bean
    public Binding sendRegisterCodeBinding() {
        return BindingBuilder.bind(sendRegisterCodeQueue())
                .to(sendCodeExchange())
                .with(SEND_REGISTER_CODE_ROUTING_KEY);
    }

    /**
     * 发送忘记密码时修改密码验证码
     *
     * @return
     */
    @Bean
    public Binding sendForgetPasswordCodeBinding() {
        return BindingBuilder.bind(sendForgetPasswordCodeQueue())
                .to(sendCodeExchange())
                .with(SEND_FORGET_PASSWORD_CODE_ROUTING_KEY);
    }
}
